import React, { PropTypes } from 'react'
import { Cascader,Form, Spin, Input,Select, InputNumber, Radio, Modal,DatePicker } from 'antd'
import moment from 'moment'
const FormItem = Form.Item

class TemplateModal extends React.Component {
  constructor (props) {
    super(props)
    this.state={
        cateList:[],
        time:'',
    }
  }
	
  handleChange1(value){
//		console.log(value)
  		const {onUsers} = this.props
  		onUsers(value)
  } 	
  	timeChange(date, dateString){
//		this.setState({ time: Date.parse(new Date(dateString))/1000 });
		this.setState({ time: dateString })
	}
  onOk=()=>{
	const { validateFields, getFieldsValue } = this.props.form
	const params = getFieldsValue()
	const { onComponent,details,onOk,isNew,onComponentUpdate} = this.props
	params.createdTime = this.state.time
	delete params.documentType1
	delete params.documentType2
	params.type = 2
	params.documentId = details.document.id
//	console.log(params)
	if(isNew == 'new'){
		onComponent(params)
	}else if(isNew == 'update'){
		const paramss = {
			id:details.document.application.id,
			opinion:params.remark,
			state:1
		}
		onComponentUpdate(paramss)
	}
	
	onOk()
  } 
  onCancels=()=>{
  	const { validateFields, getFieldsValue } = this.props.form
	const params = getFieldsValue()
  	const { onCancels,isNew,details,onComponentUpdate } = this.props
  	if(isNew == 'new'){
		onCancels()
	}else if(isNew == 'update'){
		const paramss = {
			id:details.document.application.id,
			opinion:params.remark,
			state:2
		}
		onComponentUpdate(paramss)
		onCancels()
	}
  }
    render(){
        const formItemLayout = {
          labelCol: {
            span: 6
          },
          wrapperCol: {
            span: 14
          }
        }
        const {getFieldDecorator}=this.props.form
        const {
          onOk,
          onCancels,
          visible,
          details,
          userList,
          isNew,
        }=this.props
		const userChild = [];
		for (let i = 0; i < userList.length; i++) {
			userChild.push(<Option key={userList[i].userId} value={userList[i].userId}>{userList[i].username}</Option>);
		}
		
        const modalOpts = {
          title:`${isNew === 'new' ? '档案销毁申请' : '档案销毁审核'}`,
          cancelText:`${isNew === 'new' ? '取消' : '拒绝'}`,
          visible:visible,
          onOk: this.onOk,
          onCancel:this.onCancels,
          wrapClassName: 'vertical-center-modal'
        }
       
        return (
          <Modal {...modalOpts}>
            <Form>
              <FormItem label='档案年度：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('documentType1', {
  			      initialValue:details?details.document.documentYear:'',
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={true} />
                )}
              </FormItem>       

              <FormItem label='档案名称：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('documentType2', {
  			      initialValue:details?details.document.notarialMatters:'',
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={true} />
                )}
              </FormItem>      
              
              <FormItem label='申请人：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('applicant', {
                	  initialValue:isNew == 'new'?'':details?details.document.application.applicant:'',
                  rules: [
                    {
                      required: true,
                      message: '未填写'
                    }
                  ]
                })(
                  <Select disabled={isNew == 'new'?false:true}>
                       {userChild}
                  </Select>
                )}
              </FormItem>
        		
        		  <FormItem label='申请时间：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('createdTime', {
                	  initialValue: isNew == 'new'?'':details?moment(details.document.createTime):''
                	  ,
                  rules: [
                    {
                      required: true,
                      message: '未填写'
                    }
                  ]
                })(
                  <DatePicker
		              style={{ width: 200 }}
		              disabled={isNew == 'new'?false:true}
		              placeholder="选择时间"
		              onChange={this.timeChange.bind(this)}
		              showTime
		              format="YYYY-MM-DD HH:00:00"
		            />
                )}
              </FormItem>
              
              <FormItem label='销毁原因：' hasFeedback {...formItemLayout}>
                {getFieldDecorator('describe', {
  			      initialValue:details?isNew == 'new'?"":details.document.application.describe:'',
                  rules: [
                    {
                      required: false,
                      message: '未填写'
                    }
                  ]
                })(
                  <Input disabled={isNew == 'new'?false:true} placeholder="请输入" type="textarea" rows={4}/>
                )}
              </FormItem> 
              
              {isNew == 'new' ?
              "":
	              <FormItem label='审核意见：' hasFeedback {...formItemLayout}>
	                {getFieldDecorator('remark', {
	  			     
	                  rules: [
	                    {
	                      required: false,
	                      message: '未填写'
	                    }
	                  ]
	                })(
	                  <Input placeholder="请输入" type="textarea" rows={4}/>
	                )}
	              </FormItem>               
              }
              
              
            </Form>
          </Modal>
        )
    }
}

export default Form.create()(TemplateModal)
